<?php

/**
 * 格式 
 * {
 * code: 200,
 * message: "success",// 成功/错误信息
 * data: {}/[],
 * }
 * 
 */
class ResponseModel
{
        public $code;
        public $message;
        public $data;


        public function __construct($code, $message, $data)
        {
                $this->code = $code;
                $this->message = $message;
                $this->data = $data;
        }

        public static function success($data = [])
        {
                return new ResponseModel(200, "success", $data);
        }
        public static function error($message, $data = [])
        {
                return new ResponseModel(500, $message, $data);
        }


        public function __toString()
        {
                return json_encode($this);
        }
}